package optimizers.ganeatgeneric.sin;


import java.util.HashMap;
import java.util.Map;

import fitness.Fitness;
import fitness.SineFitness;

import optimizers.commons.RunConfig;
import optimizers.ganeatgeneric.Connection;
import optimizers.ganeat.Constants;
import optimizers.ganeatgeneric.GA;
import optimizers.ganeatgeneric.Individual;
import optimizers.ganeatgeneric.Node;
import optimizers.ganeatgeneric.Species;
import optimizers.ganeat.bistableswitch.IndividualBistableSwitch;
import runconfiguration.SinConfiguration;
import visualization.ganeatgeneric.GraphDisplayer;

public class GASin extends GA {
	public GASin(RunConfig config) {
		super(config);
	}

	@Override
	public Individual getInitialIndividual() {
		HashMap<String,Object> annotations = new HashMap<String,Object>();
		annotations.put("nbSimpleSequences", 1);
		annotations.put("innovations", innovations);
		annotations.put("nodeNames", nodeNames);
		annotations.put("text", "Node gens:\r\n" + " a 28.3816 20\r\n"
						+ "Connection gens:\r\n" + " 1 a->a true 3.7959\r\n"
						+ "Exo: 0\r\n"
						+ "Pol: 0\r\n" + "Nick: 0");
		annotations.put("generationIndex", -1);
		annotations.put("individualIndex", 0);
		return new IndividualSin(new double[1],1,config,annotations);
	}

	@Override
	public Individual getNewIndividual(int count,
			Map<String, Integer> innovations2, Map<String, String> nodeNames2,
			int i, int j) {

		HashMap<String,Object> annotations = new HashMap<String,Object>();
		annotations.put("nbSimpleSequences", count);
		annotations.put("innovations", innovations2);
		annotations.put("nodeNames", nodeNames2);
		annotations.put("generationIndex", i);
		annotations.put("individualIndex", j);
		
		int size = count*count*(count+1); //size of the templates
		
		if(this.config.seqK.optimizeMechanism == RunConfig.SEQK_OPTIMIZE_YES){
			size += count;
		}
		if(this.config.inhK.optimizeMechanism == RunConfig.INHK_OPTIMIZE_YES){
			size += count*count;
		}
		if(this.config.seqC.optimizeMechanism == RunConfig.SEQC_OPTIMIZE_YES){
			size += count*(count+1);
		}
		if(this.config.exoActivity.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.polActivity.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.nickActivity.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.exoSimpleKm.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.exoInhibKm.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.polKm.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.polDoubleStrandKm.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		if(this.config.nickKm.optimizeMechanism == RunConfig.EXO_OPTIMIZE_YES){
			size += 1;
		}
		return new IndividualSin(new double[size], count, config, annotations);
	}
	
	@Override
	public String getProblemName() {
		return "Sin";
	}
	
	public static void main(String[] args) {
		Individual indiv = new GASin(new SinConfiguration())
				.getInitialIndividual();
		GraphDisplayer displayer = new GraphDisplayer("");
		displayer.addGraph(indiv.getOligoSystem().getVisualization(250, 250),
				indiv.displayTimeSereis(), indiv.printModelInTextArea());
		displayer.display();
	}

	
}
